package com.backend_pay.service;

import com.backend_pay.dao.IncomeDetailDao;
import com.backend_pay.entity.IncomeDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service //业务层bean
public class IncomeDetailService {
    //自动注入IncomeDetailDao
    @Autowired
    IncomeDetailDao incomeDetailDao;

    //保存incomeDetail
    public void save(IncomeDetail incomeDetail){
        incomeDetailDao.save(incomeDetail);
    }
    //添加一条incomeDetail,原生SQL
    public void addIncomeDetail(Integer userId, String typeIncome, Double money, String comment, Timestamp createtime){
        incomeDetailDao.addIncomeDetail(userId,typeIncome,money,comment,createtime);
    }

    //查询所有收入记录
    public List<IncomeDetail> findAllById(Integer userId){
        return incomeDetailDao.findAllById(userId);
    }
    //删除一条收入记录,jpa封装的deleteById
    public String deleteById(Integer id){
        try {
            incomeDetailDao.deleteById(id);
            return "done";
        }catch(Exception e){
            e.printStackTrace();
            return "false";
        }
    }
    //查询所有收入类型
    public String[] findAllKindOfIncome(){
        return incomeDetailDao.findAllKindOfIncome();
    }
    //按条件查询收入记录
    public List<IncomeDetail> queryIncomeByCondition(Integer userid,String typeIncome,Timestamp start,Timestamp end){
        return incomeDetailDao.queryIncomeByCondition(userid,typeIncome,start,end);
    }
    public List<IncomeDetail> queryIncomeByConditionNoType(Integer userid,Timestamp start,Timestamp end){
        return incomeDetailDao.queryIncomeByConditionNoType(userid,start,end);
    }
    //按条件查询收入的金额、收入类型
    public List<Object> queryIncomeByDate(Integer userid, Timestamp start, Timestamp end){
        return incomeDetailDao.queryIncomeByDate(userid,start,end);
    }
    //按条件查询收入的金额、时间
    public List<Object> queryIncomeGroupByDate(Integer userid, Timestamp start, Timestamp end){
        return incomeDetailDao.queryIncomeGroupByDate(userid,start,end);
    };

    //删除某一用户的所有收入信息
    public void deleteIncomeDetailByUserId(Integer userid){
        incomeDetailDao.deleteIncomeDetailByUserId(userid);
    }
}
